package com.example.sinteractactivity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.lang.String;

import static android.R.attr.data;


public class MainActivity extends AppCompatActivity {

    private EditText Edit1;
    private Button but1,but11;
    private TextView text1;
   // private String text3;
    //private int i;
    //int i;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text1 = (TextView)findViewById(R.id.text1);
        Edit1 = (EditText)findViewById(R.id.Edit1);
        but1 = (Button)findViewById(R.id.btu1);
        but11 = (Button)findViewById(R.id.btu11) ;

        but11.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt("name",1);
                bundle.putString("msg",text1.getText().toString());
                bundle.putString("msg",Edit1.getText().toString());
                Intent intent = new Intent(MainActivity.this,Main3Activity.class);
                intent.putExtras(bundle);
                startActivityForResult(intent,1);

            }
        });
        //Intent intent1 = getIntent();
        //String[] text3 = new String[20];
        //student text2 = new student();
        //text3[0] = text2;
        //text1.setText(intent1.getIntExtra("num",2)+":"+intent1.getStringExtra("msg1"));
        //Toast.makeText(this, text2, Toast.LENGTH_SHORT).show();
        but1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                bundle.putInt("name",1);
                bundle.putString("msg",text1.getText().toString());
                bundle.putString("msg",Edit1.getText().toString());
                Intent intent = new Intent(MainActivity.this,Main2Activity.class);
                intent.putExtras(bundle);
               // text3 = text3+intent.getStringExtra("msg").toString();
                startActivityForResult(intent,1);

            }
        });

    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if(requestCode==1) {
            //若当前 Activity 可能由多处返回，此处分支将更有必要
            Bundle retBundle = data.getExtras();//实例一个bundle
            String retMsg = retBundle.getString("msg1");
            String retMsg2 = retBundle.getString("msg2");
            if(retMsg!=null) {
                text1.append("小张：" + Edit1.getText().toString() + "\n" + "小王：" + retMsg + "\n");
            }
            if(retMsg2!=null) {
                text1.append("小张：" + Edit1.getText().toString() + "\n" + "小鹏：" + retMsg2 + "\n");
            }
            Edit1.setText("");
            //Edit1.setHint("收到回复：" + retMsg);
        }
    }
 //   @Override
//    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//        super.onActivityResult(requestCode, resultCode, data);
//        if(requestCode==1) {
//            //若当前 Activity 可能由多处返回，此处分支将更有必要
//            Bundle retBundle = data.getExtras();//实例一个bundle
//            String retMsg = retBundle.getString("msg1");
//            text1.append("小张："+Edit1.getText().toString()+"\n"+"小王："+retMsg+"\n");
//            Edit1.setText("");
//            //Edit1.setHint("收到回复：" + retMsg);
//        }
//    }
}
